import {
  getTimestamp
} from "./time"

const Bill = class Bill {
  constructor(props) {
    this.rechargeTime = props.rechargeTime;
    this.sendTime = props.sendTime;
    this.sendMobile = props.sendMobile;
    this.sendAccount = props.sendAccount;
    this.size = props.size;
    this.page = props.page;
  }

  getState() {
    let x = {}
    //充值时间
    if (this.rechargeTime) {
      x.rechargeTimeStart = this.rechargeTime ? getTimestamp(this.rechargeTime[0]) : undefined;
      x.rechargeTimeEnd = this.rechargeTime ? getTimestamp(this.rechargeTime[1]) + 86399999 : undefined;
    }
    //发送时间
    if (this.sendTime) {
      x.sendTimeStart = this.sendTime ? getTimestamp(this.sendTime[0]) : undefined;
      x.sendTimeEnd = this.sendTime ? getTimestamp(this.sendTime[1]) + 86399999 : undefined;
    }
    //手机号
    if (this.sendMobile) {
      if (!/^[1][3,4,5,6,7,8,9][0-9]{9}$/.test(this.sendMobile)) {
        return {
          code: '0',
          message: "请输入正确的手机号"
        }
      } else {
        x.sendMobile = this.sendMobile
      }
    }
    //账号
    if (this.sendAccount) {
      x.sendAccount = this.sendAccount
    }
    x.page = this.page
    x.size = this.size

    return x
  }
};

export default Bill
